package edu.gyc.hishiro.controller;

import edu.gyc.hishiro.model.Student;
import edu.gyc.hishiro.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/test")
public class TestStuController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/query")
    public String selectStudent(@PathParam("id") Integer id) {
        Student Student = studentService.findById(id);
        return Student.toString();
    }
    @RequestMapping("/save")
    public String saveStudent( @PathParam("name") String name, @PathParam("major") String major) {
        Student Student = new Student(name,major);
        studentService.save(Student);
        return Student.toString();
    }
    @RequestMapping("/update")
    public String updateStudent(@PathParam("id")Integer id, @PathParam("name") String name, @PathParam("major") String major) {
        Student student = studentService.findById(id);
        student.setId(id);
        student.setName(name);
        student.setMajor(major);
        studentService.update(student);
        return student.toString();
    }
    @RequestMapping("/del")
    public String updateStudent(@PathParam("id") Integer id){
        Student Student = studentService.findById(id);
        studentService.delete(id);
        return "delete "+id+" ok";
    }


}
